package com.furnitur.modules.portal.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.furnitur.common.api.Result;
import com.furnitur.modules.portal.dto.furniture.FurnitureQueryDTO;
import com.furnitur.modules.portal.service.PortalFurnitureService;
import com.furnitur.modules.portal.vo.furniture.FurnitureVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/portal/furniture")
public class PortalFurnitureController {

    @Autowired
    private PortalFurnitureService furnitureService;

    @GetMapping("/list")
    public Result<Page<FurnitureVO>> list(FurnitureQueryDTO queryDTO) {
        return Result.success(furnitureService.listFurniture(queryDTO));
    }

    @GetMapping("/hot")
    public Result getHotFurniture(@RequestParam(defaultValue = "8") Integer pageSize) {
        return Result.success(furnitureService.getHotFurniture(pageSize));
    }

    @GetMapping("/detail/{id}")
    public Result<FurnitureVO> getDetail(@PathVariable Long id) {
        return Result.success(furnitureService.getFurnitureDetail(id));
    }
    @GetMapping("/new")
    public Result<IPage<FurnitureVO>> getNewFurniture(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "12") Integer pageSize,
            @RequestParam(defaultValue = "time") String sortType) {
        Page<FurnitureVO> page = new Page<>(pageNum, pageSize);
        return Result.success(furnitureService.getNewFurniture(page, sortType));
    }

} 